var wv
// import {
//   mapState,
//   mapActions
// } from 'vuex'
import {
  share,
  AddMobileContactData
} from '@/utils/common-api.js'

// import posterShare from '@/pages_common/pages_me/singleGoodsPosters/singleGoodsPosters.vue'

export default {
  // components: {
  //   posterShare
  // },
  data() {
    return {
      carid: '', // 车id
      colorShow: 'show',
      cheight: 109,
      bannar: [],
      goodDetail: {
        cartypename: '1234',
        carname: '234',
        goodminprice: '234',
        factoryprice: '2354234',
        betweenmoney: '10',
      },
      shopDetail: {},
      colorData: '',
      imgWei: '',
      imgNum: 0,
      shareimgurl: '',
      onegood: [],
      pageShow: false,
      shareimgurl: '',
      lastImgUrl: '',
      filePath: '',

      typeid: '', //车子id
      carXqList: [], //车子详情
      listbox: '',
      sharePopupShow: false, //分享
      haibaotrue: false, //
      pageFrom: '', //从哪里进入详情
      storeidP: false,
      showPage: false,
    }
  },

  onLoad(option) {
    console.log(option)
    this.typeid = option.goodsid
    this.pageFrom = option.pageFrom ? option.pageFrom : ''

    // 字体
    this.carid = option.goodsid
  },
  // vue实例加载完成
  created() {
    this.GetGoodsCarSourceDetailsDataList() // 获取车源详情
    // this.getPosters() //单品海报
  },
  methods: {
    // ...mapActions(['setGoodsData',
    //   'setPosterBgTemplate'
    // ]), //分享

    // 获取车源列表
    async GetGoodsCarSourceDetailsDataList() {
      try {
        let data = {
          PageIndex: 1, //当前页码
          PageSize: 10, //每页条数
          Id: this.typeid, //Id
        }
        const res = await this.$api.carSource.GetGoodsCarSourceDetailsDataList(
          data
        )
        this.carXqList = res.data.list[0]
        this.showPage=true
        this.listbox = JSON.parse(JSON.stringify(res.data.list[0].colour))
        // 轮播
        this.bannar = this.carXqList.car_Img

        // 压缩图片
        this.bannar.forEach(item => {
          item.image += '!clientdetail'
        })

        // 差价
        if (this.carXqList.difference[0] === '-') {
          this.carXqList.difference = '上' + this.carXqList.difference.substr(1)
        } else {
          this.carXqList.difference = '下' + this.carXqList.difference
        }
        // 颜色
        this.colorData = this.filtercolor(this.carXqList.colour) //颜色

        this.shopDetail = this.carXqList.shop
        this.pageShow = true

        // 是否显示自家店铺
        if (this.$store.state.userInfoDetail.store.storeId === this.carXqList.store_Id) {
          this.storeidP = false
        } else {
          this.storeidP = true
        }
      } catch (err) {
        setTimeout(function() {
          uni.navigateBack()
        }, 1000)
        console.log(err)
      }
    },

    //分割颜色
    filtercolor(data) {
      data.forEach(item => {
        var arr = item.inColour.colorCoding.split('/')
        item.inColour.neiColor = arr
      })
      return data
    },
    //发起交易
    faqijiaoy(storeid) {
      if (this.$store.state.userInfoDetail.store.storeId === storeid) {
        this.$refs.uToast.show({
          title: '不可以买自己的车',
          type: 'warning',
          url: '/pages/user/index',
        })
        return
      }
      let datalist = {
        storeId: storeid,
        colorlist: this.colorData,
        id: this.carXqList.id,
        carTypeName: this.carXqList.car_Type_Name,
        configurationName: this.carXqList.configuration_Name,
        busPrice: this.carXqList.bus_Price,
        factoryPrice: this.carXqList.factory_Price,
        remarks: this.carXqList.bus_Remarks,
      }
      uni.navigateTo({
        url: '/pages_order/securedTransactions/securedTransactions?page=buycar' +
          '&datalist=' +
          encodeURIComponent(JSON.stringify(datalist)),
      })
    },
    // 打电话
    callPhone(phone) {
      //记录打电话联系的接口
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      uni.makePhoneCall({
        phoneNumber: phone,
      })
    },
    //放大图片
    bigimgList(index) {
      // 预览图片多张
      // previewImg(index) {
      let imgsArray = []
      for (let i = 0; i < this.bannar.length; i++) {
        if (this.bannar[i].image !== '') {
          imgsArray.push(this.bannar[i].image)
        }
      }
      // #ifdef MP
      uni.previewImage({
        current: index,
        urls: imgsArray,
        indicator: 'number',
        loop: true,
      })
      // #endif
      // #ifndef MP
      uni.previewImage({
        current: index,
        urls: imgsArray,
        indicator: 'number',
        loop: true,
      })
      // #endif
    },
    // 打开外观内饰
    colorCloick() {
      if (this.colorShow === 'show') {
        this.colorShow = 'isshow'
      } else {
        this.colorShow = 'show'
      }
    },
    // 获取海报图片列表
    async getPosters() {
      try {
        const {
          data
        } = await this.$api.jsonData.getPosters()
        // 为每个海报图片列表添加对应海报的type类型标识
        this.onegood = data.onegood.map(d => ({ ...d,
          type: 'onegood'
        }))
      } catch (err) {}
    },
    //分享详情海报传参
    // fenx(itemData) {
    //   let data = {
    //     bus_Price: itemData.bus_Price, //售价
    //     car_Type_Name: itemData.car_Type_Name, //汽车系列名称
    //     checked: false,
    //     configuration_Name: itemData.configuration_Name, //车子配置名称
    //     difference: itemData.difference, //差价（涨价价格前加 - 如：-1.5万为涨价1.5万）
    //     factory_Price: itemData.factory_Price, //官方指导价
    //     goodImg: itemData.car_Img[0].image, //商品主图
    //     id: itemData.id, //id
    //   }
    //   this.setPosterBgTemplate(this.onegood[0]) //海报图片list
    //   this.setGoodsData([data]) //商品信息
    //   this.haibaotrue = true //显示弹框
    // },

    // 进店
    jindian(e, a) {
      uni.navigateTo({
        url: '/pages_R/R_SearchStore/R_SearchStore?id=' + e + '&name=' + a,
      })
    },
    //跳转车型参数--未完成
    canshu() {
      uni.navigateTo({
        url: '/pages_carSource/productDcarConfigs/productDcarConfigs?carsList=' +
          encodeURIComponent(JSON.stringify(this.carXqList)),
      })
    },

    //联系卖家
    contactSeller(data) {
      if (this.pageFrom === 'chat') {
        uni.navigateBack()
        return
      }
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      this.$store.commit('news/createConversationActive', {
        user: data.store_Name, //店铺名称
        img: data.store_Topimg, //店铺头像
        lastTime: '', //
        userId: data.store_Id, //店铺id
        conversationID: 'C2C' + data.store_Id,
      })
      this.$store.commit('news/setCardInfo', {
        imgSrc: data.car_Img[0].image,
        name: data.car_Type_Name + data.configuration_Name,
        price: data.bus_Price,
        labelPrice: data.factory_Price,
        type: 'carSource',
      })
      uni.navigateTo({
        url: `/pages_news/contactSeller/contactSeller?user=${data.store_Name}&pageId=${this.typeid}`,
      })
    },

    // 跳转店铺前台页面
    goStorePage() {
      let id = this.carXqList.store_Id
      uni.navigateTo({
        url: `/pages_common/store/store?id=${id}`,
      })
    },
  },
}
